<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - 空白页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
     <!-- jqgrid-->
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">

     <link rel="stylesheet" href="__STATIC__/layout/css/channel.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">


    <link href="__STATIC__/layout/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
  
    <link rel="stylesheet" href="__STATIC__/layout/css/zTreeStyle.css" type="text/css">

    <style>
		   .radio-inline input[type=radio] {
            margin-top: 4px
        }
        .note-editable{height: 200px}
        .ren{
        	padding: 5px;
        	display: inline-block;
        	background: #DEEFFF;
        	border-radius: 5px;
        	margin:0 10px;
        }
        .ren:hover{
        	background: #AAAFFF;
        }
        #hesuan{
        	display: none;
        }
        .red{
            border-color: red;
        }
    </style>
</head>

<body style="color:#333;padding:3px; overflow-x: auto;">
    <!-- 标题 -->
    <div class="page-heade">
      <h1 class="title_color">添加常规促销申请明细</h1>
    </div>
    <!-- 标题 -->
    <div class="row-margin-top">
    <form id="f1"  method="post"  class="form-inline">
    <input type="hidden" name="detail" id="detailid" value="{$did}" />
       <table class="table-bordered table t_table">
           <tr>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >网点<span class="colorRed">*</span>：</label></td>
            <td colspan="3">
                    <div class="col-xs-4">
                         <div class="input-group"  style="display:none">
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control net" name="net" value="{$detail.net_id}">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne "  >
                                    
                                    <span class="inin">{$detail.netname}</span>
                                    <span class="close">×</span>
                                </div>
                    </div>
                    <div class="col-xs-4">
                        <button class="btn btn-primary" id="select_net">选择</button>
                        
                      
                    </div>
                </td>
           </tr>
           
          <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">产品<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                     <div class="col-xs-4">
                         <div class="input-group"  style="display:none">
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control pro" name="pro" value="{$detail.pro_id}">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne "  >
                                    
                                    <span class="inin">{$detail.pro_name}</span>
                                    <span class="close">×</span>
                                </div>
                    </div>
                    <div class="col-xs-4">
                        <button class="btn btn-primary" type="button" id="select_pro">选择</button>
                        
                      
                    </div>
                </td>
            </tr>
          
             <tr>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >促销执行时间<span class="colorRed">*</span>：</label></td>
            <td>
            <div class="form-group">
            <input type="text" id="start" class="form-control layer-date " value="{$detail.start_time}" style="min-width:100px;height: 26px;display: inline-block;" name="start">
           </div>
            <div class="form-group">
                至
            </div>
           <div class="form-group">
            <input type="text" class="form-control layer-date" value="{$detail.end_time}" style="min-width:100px;height: 26px;display: inline-block;" id="end" name="end">
           </div>
            </td>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >负责人<span class="colorRed">*</span>：</label></td>
            <td><input type="text" class="form-control" style="min-width: 220px;width: 220px" name="fuzeren" value="{$detail.fuzeren}"></td>
           </tr>
           <tr>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >预计核销时间<span class="colorRed">*</span>：</label></td>
            <td colspan="3">
                  <div class="form-group">
            <input type="text" id="yjverifyTime" class="form-control layer-date " value="{$detail.hexiao_time}" style="min-width:100px;height: 26px;display: inline-block;" name="yjverifyTime">
           </div>
            </td>
           </tr>
        </table>
    <table class="table-bordered table t_table" >
    	<thead>
        <tr>
            <th colspan="7" class="text-center font-bold">三级费用科目</th>
        </tr>
        <tr class="info">
            <th class="text-center">费用名称</th>
            <th class="text-center">未税总额(元)<span class="colorRed">*</span><span class="helpText">帮</span></th>
            <th class="text-center">费用支付方式<span class="colorRed">*</span></th>
            <th class="text-center">费用计入部门<span class="colorRed">*</span></th>
            <th class="text-center">费用计入方案</th>
            <th class="text-center">费用描述</th>
           
        </tr>
        </thead>
        <tbody id="table1">
        
        <tr class="feiyongxiang">
            <td> 
            	<div class="container-fluid">
                   {if condition="$detail.bucha eq ''"}
                        <div class="row">

                            <div class="col-xs-8">

                                <div class="input-group"  style="display:none">
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control zfid" name="feiyong_id" value="{$detail.feiyong_id}">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne "  >
                                	
                                    <span class="inin">{$detail.zftitle}</span>
                                    <span class="close">×</span>
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <button class="btn btn-primary feetree" type="button" >选择</button>
                            </div>
                        </div>
                    </div>
                    {else/}
                         <select name="feiyong_id" id="feiyong_id" class="form-control">
                        <option value="" tid='1'>请选择</option>
                        {volist name="youhui" id="row"}
                            {if condition="$detail.feiyong_id eq $row.id"}
                             <option value="{$row.id}" selected {if $row.tejiabuchatype==10} tid='2' {else/} tid="1"{/if}>{$row.title}</option>
                            {else/}

                            <option value="{$row.id}" {if $row.tejiabuchatype==10} tid='2' {else/} tid="1"{/if}>{$row.title}</option>
                            {/if}
                        {/volist}
                    </select>  
                    {/if}
                </td>
            <td><input type="text" name="zonge" class="form-control zonge nums" value="{$detail.zonge}" {if condition="$detail.bucha neq ''"} readonly {/if} ></td>
            <td>
               <select name="paymethod"  class="form-control paymethod">
                        <option value="0">请选择</option>
                        {volist name="fipay" id="row"}
                            {if condition="$detail.zfid eq $row.id"}
                                <option value="{$row.id}" selected>{$row.title}</option>
                            {else/}
                                <option value="{$row.id}">{$row.title}</option>
                            {/if}
                        {/volist}
                    </select>  
            </td>
             <td>
				<div class="container-fluid">
                        <div class="row">
                            <div class="col-xs-8">
                                <div class="input-group" style="display:none" >
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control jrbm"  name="jrbm" value="{$detail['jrbmid']}">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne " >
                                    <span class="inin">{$detail.de_name}</span>
                                    <span class="close">×</span>
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <button class="btn btn-primary select_jrbm" type="button">选择</button>
                            </div>
                        </div>
                    </div>
             </td>
             <td>
                <select name="project" class="form-control project">
                        <option value="0">请选择</option>
                        {volist name="fijiru" id="row"}
                            {if condition="$detail.fyfa eq $row.id"}
                            <option value="{$row.id}" selected>{$row.title}</option>
                            {else/}
                            <option value="{$row.id}">{$row.title}</option>
                            {/if}
                        {/volist}
                    </select>   
            </td>
             <td><input type="text" name="remark" value="{$detail.remark}" class="form-control"></td> 
            
        </tr>
        </tbody>
    </table>
      <table class="table-bordered table t_table">
      <input type="hidden" id="boxnum" value="{$detail.box_num}"/>
      	<thead></thead>
        <tbody id="protr">
            <tr>
                <td>预计销售量(箱)<span style="color:red">*</span></td>
                <td><input type="text" class="form-control nums" name="sell_num" id="sell_num" value="{$detail['sell_num']}"/></td>
                <td>需补差销量{if condition="$detail.zhejia eq ''"}<span style="color:red">*</span> {/if}</td>
                 <td><input type="text" class="form-control nums" name="bucha" id="bucha" value="{$detail['bucha']}" {if condition="$detail.zhejia eq ''"} readonly {/if} /></td>
            </tr>
            <tr class="info text-center">
                <td colspan="2"><h3>经销商价格信息</h3></td>
                <td colspan="2"><h3>供应商价格信息</h3></td>
            </tr>
            <tr>
                <td>标准出厂价(元/<span class='unit'>{$detail.unit}</span>)</td>
                <td><input type="text" class="form-control nums" id="chuchang" readonly value="{$detail['factory']}" /></td>
                <td>网点原供货价(元/{$detail.unit})<span style="color:red">*</span></td>
                <td><input type="text" class="form-control nums"  name="wangdian_yuan" id="wangdian_yuan" value="{$detail['wangdian_yuan']}"/></td>
            </tr>
            <tr>
                <td>经销商原供货价(元/<span class='unit'>{$detail.unit}</span>)</td>
                <td><input type="text" class="form-control nums"  readonly id="yuan_price" name="yuan_price" value="{$detail['yuan_price']}"/></td>
                <td>网点折价率<span style="color:red">*</span></td>
                <td><input type="text" class="form-control nums"  name="wangdian_zhejia"  id="wangdian_zhejia" value="{$detail['wangdian_zhejia']}"/>% OFF</td>
            </tr>
            <tr>
                <td>经销商折价率<span style="color:red">*</span></td>
                 <td><input type="text" class="form-control nums" name="zhejia" id="zhejia" value="{$detail['zhejia']}"  />% OFF</td>
                 <td>网点现供货价(元/<span class='unit'>{$detail.unit}</span>)<span style="color:red">*</span></td>
                <td><input type="text" class="form-control nums {if $detail.netout} red {/if}"  name="wangdian_price" id="wangdian_price" value="{$detail['wangdian_price']}"/>
                    <input type="hidden" value="{$detail.retail_high}" name="nethigh" id="retail_high"/>
                    <input type="hidden" value="{$detail.retail_low}" name="netlow" id="retail_low"/>
                </td>
            </tr>
            <tr>
                <td>经销商现供货价(元/<span class='unit'>{$detail.unit}</span>)<span style="color:red">*</span></td>
                <td><input type="text" class="form-control nums" name="now_price" id="now_price" value="{$detail['now_price']}" /></td>
                <td>网点毛利率<span style="color:red">*</span></td>
                <td><input type="text" class="form-control nums"  name="wangdianmaoli" id="wangdianmaoli" value="{$detail['wangdianmaoli']}"/>%</td>
            </tr>
            <tr>
                <td>经销商毛利率<span style="color:red">*</span></td>
                 <td><input type="text" class="form-control nums" name="maoli" id="maoli" value="{$detail['maoli']}"  />%</td>
                 <td>原零售价(元/<span class='unit'>{$detail.unit}</span>)<span style="color:red">*</span></td>
                <td><input type="text" class="form-control nums"  name="lingshou_price"  id="lingshou_price" value="{$detail['lingshou_price']}"/></td>
            </tr>
            <tr>
                <td></td><td></td>
                 <td>活动促销价(元/<span class='unit'>{$detail.unit}</span>)<span style="color:red">*</span></td>
                 <td><input type="text" class="form-control nums  {if $detail.huodongout} red {/if}" name="huodong_price" id="huodong_price" value="{$detail['huodong_price']}" />
                    <input type="hidden" value="{$detail.promotion_high}" name="cuxiaohigh" id="promotion_high"/>
                    <input type="hidden" value="{$detail.promotion_low}" name="cuxiaolow" id="promotion_low"/>
                 </td>
            </tr>
           
        </tbody>
        <tfoot>
			<tr>
            <td class="text-right" row="2">备注</td>
            <td colspan="10">
                <textarea name="beizhu" id="" rows="2" class="form-control" style="width: 50%">{$detail.beizhu}</textarea><span style="vertical-align: bottom;">(200)</span>
            </td>
        	</tr>
        </tfoot>
        
    </table>
       <div class="row sub_btn white-bg" style="width:100%;text-align:center;padding: 20px 0">
       
        <input type="button" id="baocun" class="btn btn-success" value="保存修改">
       
        <input type="button" class="btn btn-warning" value="返回" id="fanhui">
    </div>
</form>
    </div>
    <!-- 全局js -->
   <!-- 全局js -->
    <script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <!-- <script src="js/plugins/layer/layer.min.js"></script> -->

    <!-- 自定义js -->
    <!-- <script src="js/hplus.js?v=4.1.0"></script> -->
    <!-- <script type="text/javascript" src="js/contabs.js"></script> -->
     <!-- Peity -->
    <script src="__STATIC__/layout/js/plugins/peity/jquery.peity.min.js"></script>

    <!-- jqGrid -->
    <script src="__STATIC__/layout/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
    <script src="__STATIC__/layout/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>

    <!-- 自定义js -->
    <script src="__STATIC__/layout/js/content.js?v=1.0.0"></script>
     <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
    
    <!-- ztree -->
    <script type="text/javascript" src="__STATIC__/layout/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="__STATIC__/layout/js/jquery.ztree.excheck.js"></script>
    <!-- <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script> -->
    <!--统计代码，可删除-->
    <script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
    <!--统计代码，可删除-->
    <script>
    $(function(){
         $(".nums").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    $(this).val("");
                }else{
                    $(this).val(parseFloat($(this).val()).toFixed(2));
                }
            })
    })
    function shujuyanzheng(){
        var cuxiao=pf($("#huodong_price"))
        $("#huodong_price").removeClass("red");
        if($("#huodong_price").next().val()!=""){
            var cuxiaohigh=pf($("#huodong_price").next());

            if(cuxiao>cuxiaohigh&&cuxiaohigh>0){
                $("#huodong_price").addClass("red");
            }
        }
        if($("#huodong_price").next().next().val()!=""){
            var cuxiaolow=pf($("#huodong_price").next().next());

            if(cuxiao<cuxiaolow&&cuxiaolow>0){
                $("#huodong_price").addClass("red");
            }
        }
        var netxian=pf($("#wangdian_price"))
        $("#wangdian_price").removeClass("red");
        if($("#wangdian_price").next().val()!=""){
            var nethigh=pf($("#wangdian_price").next());
            if(netxian>nethigh&&nethigh>0){
                $("#wangdian_price").addClass("red");
            }
        }
        if($("#wangdian_price").next().next().val()!=""){
            var netlow=pf($("#wangdian_price").next().next());
            if(netxian<netlow&&netlow>0){
                $("#wangdian_price").addClass("red");
            }
        }
        jisuanzhejia()
    }
    //计算折价
    function jisuanzhejia(){
        if($("#bucha").val()!=""&&$("#bucha").val()!="0.00"){
            var bucha=pf($("#bucha"));
            var boxnum=pf($("#boxnum"));
            var type=$("#feiyong_id>option:selected").attr("tid")
            if(type==1){
                //经销商
                var jxsyuan=pf($("#yuan_price"))
                var jxsxian=pf($("#now_price"));
                var youhui=(jxsyuan-jxsxian)*bucha*boxnum;
            }else{
                //网点
                var netyuan=pf($("#wangdian_yuan"))
                var netxian=pf($("#wangdian_price"))
                var youhui=(netyuan-netxian)*bucha*boxnum
            }
            $("[name=zonge]").val(youhui.toFixed(2));
        }
    }
    $("#bucha").blur(function(){
        jisuanzhejia();
    })
    $("#feiyong_id").change(function(){
        jisuanzhejia();
    })
    //计算
    function pf(t){
        var num=t.val()
        if(!isNaN(parseFloat(num))){
            t.val(parseFloat(t.val()).toFixed(2))
        }else{
            t.val(0);
        }
        return parseFloat(t.val());
    }
    //活动价变动
    $("#huodong_price").blur(function(){
        var cuxiao=pf($("#huodong_price"))
        var netxian=pf($("#wangdian_price"))
        if(cuxiao==0)
            var netmao=-100;
        else
            var netmao=(cuxiao-netxian)/netxian*100;
        $("#wangdianmaoli").val(netmao.toFixed(2))
        shujuyanzheng()
    })
    //网点毛计算
    $("#wangdianmaoli").blur(function(){
        var netyuan=pf($("#wangdian_yuan"))
        var cuxiao=pf($("#huodong_price"))
        var netmao=pf($(this))
        var netxian=cuxiao/(1+netmao/100);
        $("#wangdian_price").val(netxian.toFixed(2))
        netxian=pf($("#wangdian_price"))
        var jxsxian=pf($("#now_price"));
        if(jxsxian==0)
            var jxsmao=0;
        else
            var jxsmao=(netxian-jxsxian)/jxsxian*100;
        $("#maoli").val(jxsmao.toFixed(2));
        var netzhe=(netyuan-netxian)/netyuan*100;
        $("#wangdian_zhejia").val(netzhe.toFixed(2));
        shujuyanzheng()
    })
    //网点现计算
    $("#wangdian_price").blur(function(){
        var netyuan=pf($("#wangdian_yuan"))
        var netxian=pf($(this))
        var netzhe=(netyuan-netxian)/netyuan*100;
        $("#wangdian_zhejia").val(netzhe.toFixed(2));
        var cuxiao=pf($("#huodong_price"))
        if(cuxiao==0)
            var netmao=-100;
        else
            var netmao=(cuxiao-netxian)/netxian*100;
        $("#wangdianmaoli").val(netmao.toFixed(2))
        var jxsxian=pf($("#now_price"));
        if(jxsxian==0)
            var jxsmao=0;
        else
            var jxsmao=(netxian-jxsxian)/jxsxian*100;
        $("#maoli").val(jxsmao.toFixed(2));shujuyanzheng()
    })
    //网点折价计算
    $("#wangdian_zhejia").blur(function(){
        var netyuan=pf($("#wangdian_yuan"))
        var netzhe=pf($(this));
        var netxian=netyuan-netyuan/100*netzhe;
        $("#wangdian_price").val(netxian.toFixed(2))
        netxian=pf($("#wangdian_price"))
        var cuxiao=pf($("#huodong_price"))
        if(cuxiao==0)
            var netmao=-100;
        else
            var netmao=(cuxiao-netxian)/netxian*100;
        $("#wangdianmaoli").val(netmao.toFixed(2))
        var jxsxian=pf($("#now_price"));
        if(jxsxian==0)
            var jxsmao=0;
        else
            var jxsmao=(netxian-jxsxian)/jxsxian*100;
        $("#maoli").val(jxsmao.toFixed(2));shujuyanzheng()
    })
    //网点原供货价变动
    $("#wangdian_yuan").blur(function(){
        var netyuan=pf($(this));
        var netxian=pf($("#wangdian_price"))
        var netzhe=(netyuan-netxian)/netyuan*100;
        $("#wangdian_zhejia").val(netzhe.toFixed(2));shujuyanzheng()
    })
    //经销商毛利计算
    $("#maoli").blur(function(){
        var jxsyuan=pf($("#yuan_price"))
        //网点现价
        
        var netxian=pf($("#wangdian_price"))
        var maoli=pf($(this));
        var jxsxian=netxian/(1+maoli/100);
        $("#now_price").val(jxsxian.toFixed(2));
        jxsxian=pf($("#now_price"))
        var zhejia=(jxsyuan-jxsxian)/jxsyuan*100;
        $("#zhejia").val(zhejia.toFixed(2));shujuyanzheng()
    })
    //经销商现价计算
    $("#now_price").blur(function(){
        var jxsyuan=pf($("#yuan_price"))
        var jxsxian=pf($(this));
        var zhejia=(jxsyuan-jxsxian)/jxsyuan*100;
        $("#zhejia").val(zhejia.toFixed(2));
         //网点现价
        
        var netxian=pf($("#wangdian_price"))
        //计算毛利
        var maoli=(netxian-jxsxian)/jxsxian*100;
        $("#maoli").val(maoli.toFixed(2));shujuyanzheng()
    })
    //经销商折价计算
    $("#zhejia").blur(function(){
        var zhejia=pf($(this));
        var jxsyuan=pf($("#yuan_price"))
        //现价计算
        var jxsxian=jxsyuan-jxsyuan*zhejia/100;
        $("#now_price").val(jxsxian.toFixed(2));
        jxsxian=pf($("#now_price"))
        //网点现价
        
        var netxian=pf($("#wangdian_price"))
        //计算毛利
        var maoli=(netxian-jxsxian)/jxsxian*100;
        $("#maoli").val(maoli.toFixed(2));shujuyanzheng()
    })
    </script>
    <script>
     //弹出选择我的产品
        $('body').on('click','#select_pro',function () {
            //alert(1);
           var _this = this
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    title:'产品科目树',
                    maxmin:true,
                    content:'{:url("selectProduct2")}?jid={$detail.jxs_id}',
                    btn:'确定',
                    yes:function (i,o) {
                        var id = $(o).find('iframe').contents().find('#renyuan').val()
                        var name = $(o).find('iframe').contents().find('#renyuanname').val()
                        if(id){
                            $(_this).closest('div').prev('div').find('.input-group').hide().find('.pro').val(id)
                            $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                            var jid={$detail.jxs_id};
                                $.post("{:url('xiugaigetp')}",{pid:id,jid:jid},function(re){
                                    var data=JSON.parse(re);
                                    $("#chuchang").val(data.factory)
                                    $("#yuan_price").val(data.price)
                                    $("#retail_high").val(data.retail_high)
                                    $("#retail_low").val(data.retail_low)
                                    $("#promotion_high").val(data.promotion_high)
                                    $("#promotion_low").val(data.promotion_low)
                                    $("#boxnum").val(data.box_num)
                                    $(".unit").html(data.unit)
                                     var jxsyuan=pf($("#yuan_price"))
                                    var jxsxian=pf($("#now_price"));
                                    var zhejia=(jxsyuan-jxsxian)/jxsyuan*100;
                                    $("#zhejia").val(zhejia.toFixed(2));
                                    shujuyanzheng()
                                })
                        }
                        layer.close(i)
                    }
                })
                return  false
        })
       //弹出选择我的费用科目树
        $('body').on('click','.feetree',function () {
            var _this = this
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    title:'费用科目树',
                    maxmin:true,
                    content:'{:url("selectFee")}?esuseway=1',
                    btn:'确定',
                    yes:function (i,o) {
                        var id = $(o).find('iframe').contents().find('#renyuan').val()
                        var name = $(o).find('iframe').contents().find('#renyuanname').val()
                        if(id){
                            $(_this).closest('div').prev('div').find('.input-group').hide().find('.zfid').val(id)
                            $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                        }
                        layer.close(i)
                    }
                })
                return  false
        })
        //弹出选择我的费用计入部门树
        $('body').on('click','.select_jrbm',function () {
            var _this = this
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    title:'费用计入部门树',
                    maxmin:true,
                    content:'{:url("selectJrbm")}',
                    btn:'确定',
                    btnAlign:'c',
                    yes:function (i,o) {

                        var id = $(o).find('iframe').contents().find('#renyuan').val()
                        var name = $(o).find('iframe').contents().find('#renyuanname').val()
                        if(id){
                            $(_this).closest('div').prev('div').find('.input-group').hide().find('.jrbm').val(id)
                            $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                        }
                        layer.close(i)
                    }
                })
                return  false
        })

 //返回
    $('#fanhui').click(function () {
        parent.layer.close(parent.layer.getFrameIndex(window.name))
    })
        //日期范围限制
        var start = {
            elem: '#start',
            format: 'YYYY/MM/DD',
          
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日

            }
        };
        var end = {
            elem: '#end',
            format: 'YYYY/MM/DD',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
                yjverifyTime.min=datas;
                  $.post("{:url('TiApply/gettwomon')}",{datet:datas},function(re){
                    //alert(re);
                    $("#yjverifyTime").val(re);
                })  
            }
        };
        var yjverifyTime={
            elem: '#yjverifyTime',
            format: 'YYYY/MM/DD',
            min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,

        }
        laydate(yjverifyTime);
        laydate(start);
        laydate(end);
         //弹出选择网点框
        $('#select_net').on('click',function () {
            var _this = this
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                      btn:'确定',
                    btnAlign:'c',
                    content:'{:url("selectNet2")}?index='+index+'&keyword={$detail.jxs_id}',
                      yes:function (i,o) {
                        var id = $(o).find('iframe').contents().find('#renyuan').val()
                        var name = $(o).find('iframe').contents().find('#renyuanname').val()
                        if(id){
                            $(_this).closest('div').prev('div').find('.input-group').hide().find('.net').val(id)
                            $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                        }
                        layer.close(i)
                    }
                })
                return  false
        })
          //产品网点搜索自动补全
    $(".net").bsSuggest({
        url: "{:url('netjson2')}?jid="+{$detail.jxs_id},
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
       $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)
    });
      //产品单品搜索自动补全
    $(".pro").bsSuggest({
        url: "{:url('select/productjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
       $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)
                var jid={$detail.jxs_id};
                $.post("{:url('xiugaigetp')}",{pid:keyword.id,jid:jid},function(re){
                    var data=JSON.parse(re);
                    $("#chuchang").val(data.factory)
                    $("#yuan_price").val(data.price)
                    $("#retail_high").val(data.retail_high)
                    $("#retail_low").val(data.retail_low)
                    $("#promotion_high").val(data.promotion_high)
                    $("#promotion_low").val(data.promotion_low)
                    $("#boxnum").val(data.box_num)
                    $(".unit").html(data.unit)
                     var jxsyuan=pf($("#yuan_price"))
                    var jxsxian=pf($("#now_price"));
                    var zhejia=(jxsyuan-jxsxian)/jxsyuan*100;
                    $("#zhejia").val(zhejia.toFixed(2));
                    shujuyanzheng()
                })
    });
//费用类型搜索自动补全
            $(".zfid").bsSuggest({
                url: "{:url('feiyongkemu3json',['esuseway'=>'1'])}",
                /*effectiveFields: ["userName", "shortAccount"],
                 searchFields: [ "shortAccount"],*/
                effectiveFieldsAlias:{title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)
            });
   //费用计入部门搜索自动补全
            $(".jrbm").bsSuggest({
                url: "{:url('select/jrbmjson')}",
                /*effectiveFields: ["userName", "shortAccount"],
                 searchFields: [ "shortAccount"],*/
                effectiveFieldsAlias:{title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)
            });
                  //取消单选
    $('body').on('click','.selectedOnlyOne .close',function () {
        $(this).closest('.selectedOnlyOne').hide().find('.inin').html('')
        $(this).closest('.selectedOnlyOne').prev('.input-group').show().find('input').val('')
    })

    function tijiaoyanzheng(){
        var msg=[];
        if($(".net").val()==""){
            msg["msg"]="网点不能为空";msg["state"]=2;
            return msg;
        }
        if($(".pro").val()==""){
            msg["msg"]="产品不能为空";msg["state"]=2;
            return msg;
        }
        if($("#yjverifyTime").val()==""){
            msg["msg"]="预计核销时间不能为空";msg["state"]=2;
            return msg;
        }
        if($("#start").val()==""){
            msg["msg"]="促销开始时间不能为空";msg["state"]=2;
            return msg;
        }
        if($("#end").val()==""){
            msg["msg"]="促销结束时间不能为空";msg["state"]=2;
            return msg;
        }
        if($("input[name='fuzeren']").val()==""){
            msg["msg"]="负责人必须填写";msg["state"]=2;
            return msg;
        }
        if($("input[name='feiyong_id']").val()==""){
            msg["msg"]="费用科目必须选择";msg["state"]=2;
            return msg;
        }
        if($("input[name='zonge']").val()==""||$("input[name='zonge']").val()==0){
            msg["msg"]="费用总额必须填写且不能为0";msg["state"]=2;
            return msg;
        }
        if($("input[name='paymethod']").val()==0){
            msg["msg"]="必须选择支付方式";msg["state"]=2;
            return msg;
        }
        if($("input[name='jrbm']").val()==""){
            msg["msg"]="必须选择费用计入部门";msg["state"]=2;
            return msg;
        }
        if($("input[name='project']").val()==""){
            msg["msg"]="必须选择费用计入方案";msg["state"]=2;
            return msg;
        }
        if($("input[name='sell_num']").val()==""){
            msg["msg"]="预计销售量不能为空";msg["state"]=2;
            return msg;
        }
        if($("input[name='now_price']").val()==""){
            msg["msg"]="经销商现供货价不能为空";msg["state"]=2;
            return msg;
        }
        if($("input[name='wangdian_price']").val()==""){
            msg["msg"]="网点现供货价不能为空";msg["state"]=2;
            return msg;
        }
        if($("input[name='wangdian_yuan']").val()==""){
            msg["msg"]="网点原供货价不能为空";msg["state"]=2;
            return msg;
        }
        if($("input[name='lingshou_price']").val()==""){
            msg["msg"]="网点原零售价不能为空";msg["state"]=2;
            return msg;
        }
        if($("input[name='huodong_price']").val()==""){
            msg["msg"]="网点活动价不能为空";msg["state"]=2;
            return msg;
        }
        //验证基准销量
        ck=0;
            $.ajax({
                 type: "POST",
                 url: "{:url('heduijizhun')}",
                 data: {net:$(".net").val(),pro:$(".pro").val(),start:$("#start").val(),end:$("#end").val()},
                 async:false,//注意添加async：false 同步参数
                 success:function(re){
                   // alert(re);
                    if(re==1){
                        ck=1;
                    }
                 }

            })
            if(ck==0){
                msg["msg"]="";msg["state"]=3;
                return msg;
            }
        var flag=0;
        var cuxiao=pf($("#huodong_price"))
        $("#huodong_price").removeClass("red");
        if($("#huodong_price").next().val()!=""){
            var cuxiaohigh=pf($("#huodong_price").next());

            if(cuxiao>cuxiaohigh&&cuxiaohigh>0){
                $("#huodong_price").addClass("red");flag=1;
            }
        }
        if($("#huodong_price").next().next().val()!=""){
            var cuxiaolow=pf($("#huodong_price").next().next());

            if(cuxiao<cuxiaolow&&cuxiaolow>0){
                $("#huodong_price").addClass("red");flag=1;
            }
        }
        var netxian=pf($("#wangdian_price"))
        $("#wangdian_price").removeClass("red");
        if($("#wangdian_price").next().val()!=""){
            var nethigh=pf($("#wangdian_price").next());
            if(netxian>nethigh&&nethigh>0){
                $("#wangdian_price").addClass("red");flag=1;
            }
        }
        if($("#wangdian_price").next().next().val()!=""){
            var netlow=pf($("#wangdian_price").next().next());
            if(netxian<netlow&&netlow>0){
                $("#wangdian_price").addClass("red");flag=1;
            }
        }
        if(flag==1){
            msg["msg"]="";msg["state"]=4;
            return msg;
        }else{
            msg["msg"]="";msg["state"]=1;
            return msg;
        }
    }
      $("#baocun").click(function(){
            $(".nums").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    $(this).val("");
                }else{
                    $(this).val(parseFloat($(this).val()).toFixed(2));
                }
            })
            var msg=tijiaoyanzheng();
            if(msg["state"]==2){
                swal({
                        title: "错误",
                        text: msg["msg"],
                        type: "warning"
                    });
            }else if(msg["state"]==3){
                swal({
                  title: "很抱歉",
                  text: "您申请的活动需要补录基准销量，请补录后再提交，是否马上去补录？",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "确定",
                  cancelButtonText: "取消"
                  
                },
                function(){
                    var jid={$detail.jxs_id};
                    // data: {net:$("#nets").val(),pro:$("#pros").val(),start:$("#start").val(),end:$("#end").val()},
                    var index = layer.open({
                            type:2,
                            title:'网点基准销量补录',
                            area:['80%','80%'],
                            maxmin:true,
                            content:'{:url("Ti_apply/bulu")}?net='+$(".net").val()+"&jid="+jid+"&pros="+$(".pro").val()+"&start="+$("#start").val()+"&end="+$("#end").val()
                        })
                });
            }else if(msg["state"]==4){
                if(!confirm("您申请的活动中存在不符合公司规定的单品价格，是否需要修改？点击确定前往修改，点击取消不修改")){
                    tijiao();
               }
            }else{
               tijiao();
            }
      })

      function tijiao(){
         $.ajax({
                                cache: true,
                                type: "POST",
                                url:"{:url('TiApply/updatedet')}",
                                data:$('#f1').serialize(),// 你的formid
                                async: false,
                                error: function(requests) {
                                    alert("Connection error");
                                },
                                success: function(datas) {
                                    //alert(datas);
                                   var res=JSON.parse(datas);
                                    if(res["state"]==1){
                                        swal({
                                        title: "完成",
                                        text: "操作已成功",
                                        type: "success"
                                        },function(){
                                            parent.window.location="{:url('TiApply/addform')}?aid="+res["msg"];
                                            parent.layer.close(parent.layer.getFrameIndex(window.name))
                                        });
                                    }else{
                                          swal({
                                             title: "错误",
                                             text: res["msg"],
                                             type: "warning"
                                         });
                                    }
                                }
                            });
      }
    </script>
</body>

</html>
